import { createSlice } from '@reduxjs/toolkit'

const Storage = {
    setStorage(key, value) {
        localStorage.setItem(key, JSON.stringify(value))
    },
    getStorage(key) {
        return JSON.parse(localStorage.getItem(key))
    }
}
const cart = createSlice({
    name: "cart",
    initialState: {
        cartList: Storage.getStorage('cartList') || []
    },
    reducers: {
        addCart(state, { payload }) {
            // console.log(payload);
            Storage.setStorage('clist', payload)
        }
    }
})

export const { addCart } = cart.actions
export default cart.reducer